home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_03_02
/
3n02028a
< prev
next >
Wrap
Text File
|
1991-11-15
|
17KB
|
490 lines
{Font Preview - 1.5 Program Copyright (C) Doug Overmyer 7/26/91}
program FontPreview;
{$S-} {$R PREVIEW.RES}{$R-}
uses WinTypes, WinProcs, WinDos, Strings, WObjects,StdDlgs,Fonts,Buttons;
const
id_But1 = 201; {Ownerdraw Button 1 }
id_But2 = 202; { " 2 }
id_But3 = 203; { " 3 }
id_But4 = 204; { " 4 }
id_But5 = 205; { " 5 }
id_D1Lb1 = 301; {List box in Dlg1 }
id_St1 = 401; {Static text 1 }
id_St2 = 402; {Static text 2 }
id_St3 = 403; {Static text 3 }
id_St4 = 404; {Static text 4 }
id_D3Setup = 501; {Setup button in Dlg3}
id_D3EC1 = 506; {Edit control in Dlg3}
id_D3OK = 521; {OK button in Dlg3 }
id_lb2 = 601; {FBox list box control}
idm_About = 801; {menu id for PV_About menu}
idm_RunCP = 802; {menu id for run control panel}
idm_RunATM = 803; {menu id for run ATM }
type
TPVApplication = object(TApplication)
procedure InitMainWindow;virtual;
end;
PPVDlg1 = ^TPVDlg1; {Font Sizes Dialog}
TPVDlg1 = object(TDialog)
FontSize: Integer;
procedure WMInitDialog(var Msg:TMessage);virtual wm_First+wm_InitDialog;
procedure IDD1LB1(var Msg:TMessage);virtual id_First+id_D1Lb1;
end;
PPVDlg2 = ^TPVDlg2; {String Dialog}
TPVDlg2 = object(TDialog)
DCType:Char;
procedure WMInitDialog(var Msg:TMessage);virtual wm_First+wm_InitDialog;
end;
type {Child win to display sample text}
PFontWindow = ^TFontWindow;
TFontWindow = object(TWindow)
FontHeight: LongInt;
constructor Init(AParent: PWindowsObject; ATitle: PChar);
procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
end;
type {MainWindow of Application}
PPVWindow = ^TPVWindow;
TPVWindow = object(TWindow)
FWin:PFontWindow; {child window displaying typeface sample}
FBox:PListBox; {List box of available type faces}
Fonts:PFonts;
LogPixY:Integer;
Bn1,Bn2,Bn3,Bn4,Bn5:PODButton;
Dlg1 : PPVDlg1; {Select font size dialog}
St1,St2,St3,St4:PStatic;
TextString:Array[0..80] of Char; {to display in FWin}
FontSelection:Integer; {Index into Fonts }
FontSize:Integer; {Current font size }
constructor Init(AParent:PWindowsObject;ATitle:PChar);
destructor Done;virtual;
procedure SetupWindow;virtual;
procedure Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);virtual;
procedure LoadFBox;
procedure WMDrawItem(var Msg:TMessage);virtual wm_First + wm_DrawItem;
procedure WMSize(var Msg:TMessage);virtual wm_First+wm_Size;
procedure WMSetFocus(var Msg:TMessage);virtual wm_First+wm_SetFocus;
procedure IDBut1(var Msg:TMessage);virtual id_First+id_But1; {Information}
procedure IDBut2(var Msg:TMessage);virtual id_First+id_But2; {Size}
procedure IDBut3(var Msg:TMessage);virtual id_First+id_But3; {String}
procedure IDBut4(var Msg:TMessage);virtual id_First+id_But4; {Text Metrics}
procedure IDBut5(var Msg:TMessage);virtual id_First+id_But5; {Exit}
procedure IDLB2(var Msg:TMessage);virtual id_First+id_lb2;
procedure EnumerateFonts;virtual;
procedure WMSysCommand(var Msg:TMessage);virtual wm_First+wm_SysCommand;
function GetIC:HDC;virtual;
end;
{*************************** G l o b a l s **************************}
var
MainWin:PPVWindow;
{*************************** M e t h o d s *************************}
procedure TPVApplication.InitMainWindow;
begin
MainWindow := New(PPVWindow,Init(nil,'Font Preview'));
MainWin := PPVWindow(MainWindow);
end;
{************************** TPVWindow ******************************}
constructor TPVWindow.Init(AParent:PWindowsObject;ATitle:PChar);
begin
TWindow.Init(AParent,ATitle);
Attr.X := 20; Attr.Y := 25; Attr.W := 595; Attr.H := 260;
Bn1 := New(PODButton,Init(@Self,id_But1,'About',0,0,50,50,False,'PV_Bn1'));
Bn2 := New(PODButton,Init(@Self,id_But2,'Font Size',50,0,50,50,False,'PV_Bn2'));
Bn3 := New(PODButton,Init(@Self,id_But3,'String',100,0,100,50,False,'PV_Bn3'));
Bn4 := New(PODButton,Init(@Self,id_But4,'TM',200,0,50,50,False,'PV_Bn4'));
Bn5 := New(PODButton,Init(@Self,id_But5,'Exit',250,0,50,50,False,'PV_Bn5'));
St1 := New(PStatic,Init(@Self,id_St1,'',315,5,240,18,75));
St2 := New(PStatic,Init(@Self,id_St2,'',315,26,240,18,75));
St3 := New(PStatic,Init(@Self,id_ST3,'',310,3,250,44,75));
St4 := New(PStatic,Init(@Self,id_St4,'',5,55,100,18,75));
St2^.Attr.Style := St2^.Attr.Style or ss_LeftNoWordWrap;
St3^.Attr.Style := St3^.Attr.Style or ss_BlackFrame;
St4^.Attr.Style := St4^.Attr.Style or ss_Left;
FontSelection := 0;
FontSize := 48;
StrCopy(TextString,'');
Fonts := New(PFonts,Init);
EnumerateFonts;
FWin := New(PFontWindow,Init(@Self,ATitle));
With FWin^.Attr do Style := Style or ws_Child or ws_HScroll or ws_VScroll or ws_Border ;
FBox := New(PListBox,Init(@Self,id_lb2,0,0,0,0));
With FBox^.Attr do Style := Style and not lbs_Sort;
end;
procedure TPVWindow.SetupWindow;
begin
TWindow.SetupWindow;
SetClassWord(HWindow,GCW_HIcon,LoadIcon(HInstance,'PV_Icon'));
AppendMenu(GetSystemMenu(hWindow,false),MF_Separator,0,nil);
AppendMenu(GetSystemMenu(hWindow,false),0,idm_RunCP,'Run Control Panel');
AppendMenu(GetSystemMenu(hWindow,false),0,idm_RunATM,'Run ATM');
AppendMenu(GetSystemMenu(hWindow,false),MF_Separator,0,nil);
AppendMenu(GetSystemMenu(hWindow,false),0,idm_About,'About...');
LoadFBox;
end;
procedure TPVWindow.Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);
var
ThePen,OldPen:HPen;
TheBrush,OldBrush:HBrush;
begin
TheBrush := GetStockObject(LtGray_Brush);
ThePen := CreatePen(ps_Solid,1,$00000000);
OldPen := SelectObject(PaintDC,ThePen);
OldBrush := SelectObject(PaintDC,TheBrush);
Rectangle(PaintDC,0,0,1024,50);
SelectObject(PaintDC,OldBrush);
SelectObject(PaintDC,OldPen);
DeleteObject(ThePen);
end;
procedure TPVWindow.WMDrawItem(var Msg:TMessage);
var
PDIS : ^TDrawItemStruct;
begin
PDIS := Pointer(Msg.lParam);
case PDIS^.CtlType of
odt_Button:
case PDIS^.CtlID of
id_But1 :Bn1^.DrawItem(Msg);
id_But2 :Bn2^.DrawItem(Msg);
id_But3 :Bn3^.DrawItem(Msg);
id_But4 :Bn4^.DrawItem(Msg);
id_But5 :Bn5^.DrawItem(Msg);
end;
end;
end;
destructor TPVWindow.Done;
begin
Dispose(BN1,Done);Dispose(Bn2,Done);Dispose(Bn3,Done);
Dispose(Bn4,Done);Dispose(Bn5,Done);Dispose(St1,done);
Dispose(St2,Done);Dispose(St3,Done);Dispose(St4,Done);
TWindow.Done;
end;
procedure TPVWindow.WMSize(var Msg:TMessage);
begin
SetWindowPos(FBox^.HWindow,0,-1,75,(Msg.LParamLo div 3)+1,
((Msg.LParamHi-70) ),swp_NoZOrder);
SetWindowPos(FWin^.HWindow,0,(Msg.LParamLo div 3)-1,49,
(Msg.LParamLo * 2 div 3)+1,(Msg.LParamHi-48),swp_NoZOrder);
end;
procedure TPVWindow.WMSetFocus(var Msg:TMessage);
begin
SetFocus(FBox^.HWindow);
end;
procedure TPVWindow.IDBut1(var Msg:TMessage);
begin
Application^.ExecDialog(New(PDialog,Init(@Self,'PV_About')));
end;
procedure TPVWindow.IDBut2(var Msg:TMessage);
begin
Dlg1 := new(PPVDlg1,Init(@Self,'PV_Dlg1'));
Application^.ExecDialog(Dlg1);
if (Dlg1^.FontSize) <> 0 then InvalidateRect(Fwin^.HWindow,nil,True);
end;
procedure TPVWindow.IDBut3(var Msg:TMessage);
begin
If Application^.ExecDialog(New(PInputdialog,Init(@Self,'Font String',
'Enter text:',TextString,SizeOf(TextString)))) <> 1 then StrCopy(TextString,'');
InvalidateRect(FWin^.HWindow,nil,True);
end;
procedure TPVWindow.IDBut4(var Msg:TMessage);
var
Dlg : PPVDlg2;
begin
Dlg :=New(PPVDlg2,Init(@Self,'PV_Dlg2'));
Dlg^.DCType := 'S';
Application^.ExecDialog(Dlg);
Dlg :=New(PPVDlg2,Init(@Self,'PV_Dlg2'));
Dlg^.DCType := 'P';
Application^.ExecDialog(Dlg);
end;
procedure TPVWindow.IDBut5(var Msg:TMessage);
begin
CloseWindow;
end;
procedure TPVWindow.LoadFBox;
var
Indx : Integer;
Font : PFontItem;
Buf